package com.earthchen.service.user.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.earthchen.dao.user.PostMapper;
import com.earthchen.domain.entity.user.Post;
import com.earthchen.service.user.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;


/**
 * @author earthchen
 * @date 2018/9/27
 **/
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements PostService
{

    @Autowired
    private PostMapper postMapper;

    @Override
    public List<Post> selectPostAll()
    {
        return list(new QueryWrapper<>());
    }

    @Override
    public List<Post> selectPostsByUserId(Long userId)
    {
        List<Post> userPosts = postMapper.selectPostsByUserId(userId);

        List<Post> posts = selectPostAll();

        for (Post post : posts)
        {
            for (Post userRole : userPosts)
            {
                if (post.getId().longValue() == userRole.getId().longValue())
                {
                    post.setFlag(true);
                    break;
                }
            }
        }
        return posts;
    }
}
